package com.scqkxx.gamebox.activity.group;

import android.content.ContentValues;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.avos.avoscloud.SaveCallback;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.activities.utils.ActivityUtil;
import com.scqkxx.gamebox.activity.group.adapter.GroupMemberAdapter;
import com.scqkxx.gamebox.databinding.ActivityGroupMembersBinding;
import com.scqkxx.gamebox.databinding.ActivityJoinGroupBinding;
import com.scqkzqtz.base.base.BaseActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GroupMembersActivity extends BaseActivity<ActivityGroupMembersBinding> {

    private GroupMemberAdapter groupMemberAdapter;
    private List<AVObject> dataList = new ArrayList<>();


    @Override
    public int setLayoutId() {
        return R.layout.activity_group_members;
    }

    @Override
    public void init() {
        binding.titleView.setOnTitleClickListener(mTitleType -> finish());

        groupMemberAdapter = new GroupMemberAdapter(R.layout.item_group_member, dataList);
        binding.rvGroupMembers.setLayoutManager(new LinearLayoutManager(this));
        binding.rvGroupMembers.setAdapter(groupMemberAdapter);

        String groupId = getIntent().getStringExtra("groupId");
        ContentValues contentValues = new ContentValues();
        contentValues.put("groupId",groupId);
        binding.btInviteMember.setOnClickListener(view -> ActivityUtil.switchTo(this, GroupInviteCodeActivity.class,contentValues));

        AVQuery<AVObject> query = AVQuery.getQuery("GroupUser");
        query.whereEqualTo("groupId",Integer.parseInt(groupId));
        query.findInBackground(new FindCallback<AVObject>() {
            @Override
            public void done(List<AVObject> avObjects, AVException e) {
                Log.i("GroupUser",avObjects+"");
                if (e == null && avObjects != null && avObjects.size() > 0) {
                    dataList.clear();
                    dataList.addAll(avObjects);
                    groupMemberAdapter.setNewData(dataList);
                }
            }
        });
    }
}
